// pages/cultrueConpous/myCultrueConpous/index.js
var common = require("../../../public.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    userInfo: '',
    token: "",
    active: '-1',
    discountCouponList: [],
    discountTypeList: [],
    noUseMoney: '', // 未使用卷总额
    adminCouponList: '',
    adminDiscountTypeList: '',
    isLoadingBusy: false,
    cityCouponList: [],
    cityCouponListss: [],
    isTouch: false, //是否可以滚动  true不可
    tengZhou: [], //滕州券包集合
  },
  onLoad: function (options) {
   
  },
  onClickHide(){
     this.setData({
       isTouch:false
     })
  },
  onShow: function () {
    const that = this
    wx.getStorage({
      key: 'user',
      success: function (res) {
        that.setData({
          userInfo: res.data.user,
          token: res.data.token,
        }, function () {
          // 测试数据
          that.getMyUseFullCityDisCouponList()
        })
      }
    })
  },
  // 激活
  toJiHuo(e) {
    let status = e.currentTarget.dataset.status.status
    var acId = e.currentTarget.dataset.status.acId
    var couponNo = e.currentTarget.dataset.status.couponNo
    var managerId = e.currentTarget.dataset.status.managerId
    if (status == 9) {   //去激活
      wx.navigateTo({
        url:
          '/packageB/pages/jihuo/index?acId=' + acId +
          '&couponNo=' + couponNo
          + '&managerId=' + managerId
          + '&status=' + status
          + '&tengZhou=' + JSON.stringify(this.data.tengZhou)

      })
      // 7
    } else if (status == 7) {  //拒绝编辑
      wx.navigateTo({
        url:
          '/packageB/pages/jihuo/index?acId=' + acId +
          '&couponNo=' + couponNo
          + '&managerId=' + managerId
          + '&status=' + status
          + '&tengZhou=' + JSON.stringify(this.data.tengZhou)
      })
    }
  },
  getMyUseFullCityDisCouponList() {
    this.setData({
      isLoadingBusy: true
    })
    let that = this
    let tempJson = {
      userId: that.data.userInfo.id,
      token: that.data.token
    }
    common.post('/cityDisCoupon/getMyUseFullCityDisCouponList', tempJson, function (res) {
      if (res.status === 200) {
        console.log(res.data, "ooooo9999999")
        res.data.adminCouponList.map((item, index) => {
          console.log(item)
          if(item.status==5){
               that.setData({
                 isTouch:true
               })
          }
        })
        if (tempJson.couponType) {
          that.setData({
            discountCouponList: res.data,
            adminCouponList: [],
            cityCouponList: [],
            cityCouponListss: []
            // discountTypeList: res.data.discountTypeList,
            // noUseMoney: res.data.noUseMoney && res.data.noUseMoney.toFixed(2),
          })
        } else { //初始化全部列表
          let newDiscountTypeList = []
          let newAdminDiscountTypeList = []
          //添加type   1==市券 ，2==平台券
          res.data.discountTypeList.map((v, i) => {
            newDiscountTypeList.push({
              ...v,
              type: 1
            })
          })
          res.data.adminDiscountTypeList.map((v, i) => {
            newAdminDiscountTypeList.push({
              ...v,
              type: 2
            })
          })
          var cityCouponList = []
          var cityCouponListss = []
          for (var i = 0; i < res.data.adminCouponList.length; i++) {
            // 过滤滕州券
            console.log(res.data.adminCouponList[i].tzAreaFlag)
            var tengZhou = res.data.adminCouponList.filter((x) => x.tzAreaFlag == 0)
            if (res.data.adminCouponList[i].isComposit == 1) { //isComposit ==1 不可叠加
              cityCouponList.push(res.data.adminCouponList[i])
            } else {
              cityCouponListss.push(res.data.adminCouponList[i])
            }
          }
          // console.log( cityCouponListss,"222222")
          // console.log( cityCouponList,"111111")
          that.setData({
            tengZhou,
            discountCouponList: res.data.discountCouponList,
            discountTypeList: [...newDiscountTypeList, ...newAdminDiscountTypeList],
            // adminCouponList: res.data.adminCouponList,
            cityCouponList,
            cityCouponListss,
            noUseMoney: res.data.noUseMoney && res.data.noUseMoney.toFixed(2),
          }, () => {
            console.log(that.data.cityCouponList, "000000")
          })
        }
      } else {
        // 非200
        common.showRequestErrMsg(res)
      }
    },
      function () {
        that.setData({
          isLoadingBusy: false
        })
      })
  },
  toPlatformCouponsDetail(e) {
    console.log(e)
    let id = e.currentTarget.dataset.item.acId
    let flags = 3
    let endTime = e.currentTarget.dataset.item.endTime
    // if (e.currentTarget.dataset.item.type == 4) 
    // // console.log("ppppppppppp")
  
    // let { flags, id } = e.currentTarget.dataset
    wx.navigateTo({
        url: `/packageB/pages/cultureCoupons/platformCoupons/index?dcId=${id}&endTime=${endTime}&flag=${flags}&isOffLine=${this.data.isOffLine}&from=detail`
    })
  },
  toCultureCouponsDetail(e) {
    // console.log(e)
    let id = e.currentTarget.dataset.item.dcId
    let no = e.currentTarget.dataset.item.couponNo
    // wx.navigateTo({
    //   url: '/pages/cultureCoupons/cultureCouponsDetail/index?dcId=' + id + '&from=detail' + '&no=' + no,
    // })

    wx.navigateTo({
      url: '/packageB/pages/cultureCoupons/cultureCouponsDetail/index?dcId=' + id + '&from=detail' + '&no=' + no,
    })
  }

})